package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.FinancingProductService;
import service.impl.FinancingProductServicImpl;

/**
 * Servlet implementation class CheckFinProServlet
 */
@WebServlet("/CheckFinProServlet")
public class CheckFinProServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String id =request.getParameter("pid"); //获取前端的参数
		System.out.println("id---: "+ id);
		
		//调用service方法执行查询
		FinancingProductService fpService = new FinancingProductServicImpl();
		
		//按 id (产品代码) 查询
		int res = fpService.count(id);//1  0
		
		PrintWriter out = response.getWriter();
		out.print("{\"msg\":"+res+"}"); //  {"msg":res }
		//response.getWriter().print(" {\"res\":"+res+" }"); //  {"res":res }
		out.flush();
		out.close();
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
